package com.xr.singleton.controller.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.xr.singleton.model.dto.RestResponse;
import com.xr.singleton.model.entity.UserEntity;
import com.xr.singleton.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("admin/user")
@Slf4j
public class UserController{

    @Autowired
    private IUserService userService;

    @RequestMapping("/list")
    @ResponseBody
    public RestResponse listByPage(@RequestParam(defaultValue = "0") Integer pageNum, @RequestParam(defaultValue = "10") Integer pageSize){
        IPage<UserEntity> page = userService.listByPage(pageNum, pageSize);
        return RestResponse.ok(page);
    }

    @ResponseBody
    @RequestMapping("/listAll")
    public Object list( @RequestBody(required = false) Map<String, Object> params, HttpServletRequest request) {
        List<UserEntity> list = userService.list( params);
        return  RestResponse.ok(list);
    }

    @ResponseBody
    @RequestMapping("/info/{id}")
    public Object info(@PathVariable Long id, HttpServletRequest request) {
        UserEntity userEntity = userService.getInfoById(id);
        return RestResponse.ok(userEntity);
    }

    @ResponseBody
    @RequestMapping("/login")
    public Object login(HttpServletRequest request) {
        Map<String, Object> oMap = new HashMap<>();
        oMap.put("token", "fdsjfhjkdshfkldsajfjasdfbjsdkfhsdajfj");
        return RestResponse.ok(oMap);
    }



}
